// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/super/FFInk.dart';
import 'package:mybase/base/tool/color/FFColor.dart';
import 'package:mybase/base/tool/empty/FFEmpty.dart';
import 'package:mybase/base/tool/globalMethod/FFSafeValue.dart';
import 'package:mybase/base/tool/globalMethod/FFScript.dart';
import 'package:mybase/base/tool/platformUtils/FFPlatform.dart';
import 'package:mybase/base/tool/pprint/FFLog.dart';
import 'package:mybase/base/widget/layout/FFImageButton.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFNavi2.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFListScaffold.dart';
import 'package:myuis/constant/PackageValue.dart';
import 'package:myuis/manager/MyuisManager.dart';
import 'package:myuis/tools/GoSystemPageTool.dart';
import 'package:myuis/language/LanguageValue.dart';

class CancelSubPage extends FFListScaffold {
  String? name;

  CancelSubPage({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  CancelSubPageState createState() => CancelSubPageState();
}

class CancelSubPageState extends FFListScaffoldState {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  CancelSubPage get widget => super.widget as CancelSubPage;

  ///刷新控制
  @override
  IFFRefresh? get iffRefresh => refresh;
  late CancelSubPageStateRefresh refresh = CancelSubPageStateRefresh(state: this);

  @override
  FFPageSpacingParam? get ffPageSpacingParam => FFPageSpacingParam(bottomSpacing: true);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNavi2.createNavi(context, title: LanguageValue.cancelSub(getContext()));
  }

  // @override
  // Widget? ffNaviBottomFixedArea(BuildContext context) {
  //   return FFInk(
  //     child: FFTextButton(
  //       onClick: () {
  //         GoSystemPageTool.gotoSystemSubscribePage();
  //       },
  //       text: LanguageValue.cancelSub(context),
  //       fontSize: 17.sp,
  //       fontColor: Colors.white,
  //       padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.w),
  //       margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.w, bottom: 16.w),
  //       maxLines: 10,
  //       alignment: Alignment.center,
  //       textAlign: TextAlign.center,
  //       decoration: BoxDecoration(
  //         borderRadius: BorderRadius.circular(16.w),
  //         color: getTheme().getMainColor(),
  //       ),
  //     ),
  //   );
  // }

  @override
  Widget ffItem(BuildContext context, int index) {
    CancelSubEntity? entity = globalSafeValueFromList(datas, index);
    if (entity == null) return Container();

    return FFLineContainer(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(16.w),
        color: Colors.grey.withAlpha(50),
      ),
      padding: EdgeInsets.all(16.w),
      margin: EdgeInsets.only(
        left: 16.w,
        right: 16.w,
        bottom: 20.w,
      ),
      direction: Axis.vertical,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: globalScript2(() {
        List<Widget> list = [];
        if (!FFEmpty.stringIsEmpty(entity.info)) {
          list.add(
            FFTextButton(
              text: index == 0 ? "${entity.info}" : "${index}、${entity.info}",
              fontSize: 16.sp,
              fontColor: Colors.white,
              maxLines: 999999,
              fontLineHeight: 1.3,
            ),
          );
        }

        if (!FFEmpty.stringIsEmpty(entity.img)) {
          list.add(
            FFImageButton(
              margin: EdgeInsets.only(top: 12.w),
              image: Image.asset(
                entity.img ?? "",
                package: PackageValue.package,
              ),
            ),
          );
        }

        return list;
      }),
    );
  }
}

class CancelSubPageStateRefresh with MFFRefresh {
  CancelSubPageState state;

  CancelSubPageStateRefresh({
    required this.state,
  });

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    List<CancelSubEntity> list = [];

    if (FFPlatform.isAndroid) {
      list = [
        CancelSubEntity(
          img: "",
          info: LanguageValue.cancelSubInfo(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/androidcancel1.png",
          info: LanguageValue.androidSub(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/androidcancel2.png",
          info: LanguageValue.androidSub2(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/androidcancel3.png",
          info: LanguageValue.androidSub3(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/androidcancel4.png",
          info: LanguageValue.androidSub4(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/androidcancel5.png",
          info: LanguageValue.androidSub5(getContext()),
        ),
      ];
    } else {
      list = [
        CancelSubEntity(
          img: "",
          info: LanguageValue.cancelSubInfo(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/ioscancel1.PNG",
          info: LanguageValue.iosSub1(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/ioscancel2.PNG",
          info: LanguageValue.iosSub2(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/ioscancel3.PNG",
          info: LanguageValue.iosSub3(getContext()),
        ),
        CancelSubEntity(
          img: "assets/images/cancelsub/ioscancel4.PNG",
          info: LanguageValue.iosSub4(getContext()),
        ),
      ];
    }

    return R(rStatus: RStatus.result, data: list);
  }
}

class CancelSubEntity {
  String? info;
  String? img;

  CancelSubEntity({
    required this.info,
    required this.img,
  });
}
